package com.beinhospital_sw21_h2_05.beinhospitalsw21h205.mapper;

import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Doctor;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Linshi2;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.UserTable;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * MyBatis Mapper接口，用于与数据库表Doctor和UserTable进行交互
 */
@Mapper
public interface DoctorMapper {

    /**
     * 查询医生信息
     * @param doctorName 医生姓名
     * @return 医生列表
     */
    List<Linshi2> list(String doctorName);

    /**
     * 根据医生ID删除医生
     * @param doctorID 医生ID
     */
    @Delete("delete from Doctor where doctorID = #{doctorID}")
    void delete(Integer doctorID);

    /**
     * 插入医生信息
     * @param doctor 医生对象
     */
    @Insert("insert into Doctor(UserID,DoctorName,DepartmentID) values(#{UserID},#{DoctorName},#{DepartmentID})")
    void insert(Doctor doctor);

    /**
     * 插入用户信息
     * @param user 用户对象
     */
    @Insert("insert into UserTable(Username,Password,Role) values(#{Username},#{Password},#{Role})")
    void insertUser(UserTable user);

    /**
     * 根据用户名查询用户ID
     * @param username 用户名
     * @return 用户ID
     */
    @Select("select UserID from UserTable where Username = #{username}")
    Integer getUserID(String username);

    /**
     * 根据科室名查询科室ID
     * @param departmentName 科室名
     * @return 科室ID
     */
    @Select("select DepartmentID from Department where DepartmentName = #{departmentName}")
    Integer getDepartmentID(String departmentName);

    /**
     * 更新用户信息
     * @param user 用户对象
     */
    @Update("update UserTable set Username = #{Username},Password = #{Password} where UserID = #{UserID}")
    void updateUser(UserTable user);

    /**
     * 根据医生ID查询用户ID
     * @param doctorID 医生ID
     * @return 用户ID
     */
    @Select("select UserID from Doctor where DoctorID = #{doctorID}")
    Integer getUserID2(Integer doctorID);

    /**
     * 更新医生信息
     * @param doctor 医生对象
     */
    @Update("update Doctor set DoctorName = #{DoctorName},DepartmentID = #{DepartmentID} where DoctorID = #{DoctorID}")
    void updateDoctor(Doctor doctor);

    /**
     * 根据用户ID删除用户
     * @param user 用户ID
     */
    @Delete("delete from UserTable where UserID = #{user}")
    void deleteUser(Integer user);
}
